﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GXRTBTC.PublicClassLibrary.Model
{
    /// <summary>
    /// 认证信息
    /// </summary>
    public class VerifInfo
    {
        /// <summary>
        /// 操作用户
        /// </summary>
        public string userName { get; set; } = "";
        /// <summary>
        /// 用户编码
        /// </summary>
        public string userCode { get; set; } = "";
        /// <summary>
        /// 真实名称（姓名）
        /// </summary>
        public string realname { get; set; } = "";
        /// <summary>
        /// 是否验证
        /// 前台传递不验证参数正确时为false不验证
        /// </summary>
        public bool verif { get; set; } = true;
        /// <summary>
        /// 查看、控制权限
        /// 默认就有查看权限
        /// </summary>
        //public string authority { get; set; } = "check";
        public Dictionary<string, string> authority { get; set; } = new Dictionary<string, string>() { { "check", "" } };
        /// <summary>
        /// 角色，可能多个
        /// </summary>
        public Dictionary<string, string> roles { get; set; } = new Dictionary<string, string>();
        /// <summary>
        /// 分中心
        /// </summary>
        public Dictionary<string, string> branchUnit { get; set; } = new Dictionary<string, string>();
        /// <summary>
        /// 维护部
        /// </summary>
        public Dictionary<string, string> mainTainDept { get; set; } = new Dictionary<string, string>();
        /// <summary>
        /// 是否超级权限，即技术中心或者无线传播枢纽台，可以看全部分中心
        /// 45010000 无线传播枢纽台
        /// 45000000 技术中心
        /// </summary>
        public bool super
        {
            get
            {
                return roles.ToDictionary(val => val.Key, val => "").ContainsKey("superadmin");
            }
        }

        /// <summary>
        /// 值班员
        /// 基础查看、控制权限
        /// </summary>
        public bool controler
        {
            get
            {
                return !verif || super || control;
            }
        }

        /// <summary>
        /// 只有查看权限
        /// </summary>
        public bool viewer
        {
            get
            {
                return !verif || controler || super || control || check;
            }
        }

        /// <summary>
        /// 是否控制权限
        /// </summary>
        private bool control
        {
            get
            {
                return authority.ToDictionary(val => val.Key, val => "").ContainsKey("control");
            }
        }
        /// <summary>
        /// 是否查看权限
        /// </summary>
        private bool check
        {
            get
            {
                return authority.ToDictionary(val => val.Key, val => "").ContainsKey("check");
            }
        }
    }
}
